﻿/***************************************************/
/*** file:IHanleServer.cs                        ***/
/*** date:2010-08-15                             ***/
/*** author:huas                                 ***/
/*** function:implement database     interface   ***/
/***************************************************/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;
using IM.Common;

namespace IM.Database
{
    public abstract class DataProvider
    {
        protected static string connString = String.Empty;
        private static DataProvider dataProvider = null;

        /// <summary>
        /// 根据数据库类型创建数据库实例。
        /// </summary>
        /// <param name="providerType"></param>
        /// <param name="connString"></param>
        /// <returns></returns>
        public static DataProvider CreateInstance(DataProviderType providerType, string connString)
        {
            if (dataProvider == null || DataProvider.connString != connString)
            {
                // 当dataProvider为空或者连接字符串发生改变时，重新创建数据库实例。
                DataProvider.connString = connString;
                dataProvider = (DataProvider)Assembly.GetExecutingAssembly().CreateInstance("IM.Database." + providerType.ToString());
            }
            return dataProvider;
        }

        /// <summary>
        /// 取所有在线用户列表。
        /// </summary>
        /// <returns></returns>
        public abstract DataTable GetAllOnlineUsers();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="verify_result"></param>
        /// <param name="account_id"></param>
        /// <returns></returns>
        public abstract bool GetAccountDetail(ref s2c_account_verify_result verify_result, int account_id);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="strAccount"></param>
        /// <param name="strPwd"></param>
        /// <param name="account_id"></param>
        /// <returns></returns>
        public abstract bool VerifyAccount(string strAccount, string strPwd, ref int account_id);
  
    }

    /// <summary>
    /// 使用的数据库类型
    /// </summary>
    public enum DataProviderType
    {
        /// <summary>
        /// Access
        /// </summary>
        OleDbProvider,
        /// <summary>
        /// MSSql
        /// </summary>
        SqlServerProvider,
        /// <summary>
        /// MySql
        /// </summary>
        MySqlProvider
    }
}
